/*
 * @Author: your name
 * @Date: 2024-06-04 11:09:37
 * @LastEditTime: 2024-06-04 13:34:40
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \.leetcode\763.划分字母区间.cpp
 */
/*
 * @lc app=leetcode.cn id=763 lang=cpp
 *
 * [763] 划分字母区间
 */

// @lc code=start
class Solution {
public:
    vector<int> partitionLabels(string s) {
        
        int table[26] = {0};
        for (int i = 0; i < s.size(); i++)
        {
            table[s[i]-'a'] = i;
        }
        vector<int> result;
        int left = 0;
        int right = 0;
        for (int i = 0; i < s.size(); i++){
            right = max(right, table[s[i]-'a']);
            if(i == right){
                result.emplace_back(right-left+1);
                left = i+1;
            }
        }
        return result;
        
    }
};
// @lc code=end

